import React from "react"
import { Route, Redirect } from "react-router-dom"
import { hasToken } from '../../utils/storage'
function AuthRouter({ component: Component, ...rest }) {
    return (
        <Route
            {...rest}
            render={(props) => {
                // console.log(8, "props", props)
                if (hasToken()) {
                    return <Component {...props}></Component>
                } else {
                    return (
                        <Redirect
                            to={{ pathname: "/login", state: { from: props.location } }}
                        ></Redirect>
                    )
                }
            }}
        ></Route>
    )
}

export default AuthRouter
